package com.example.download.ViewModel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.example.download.R
import com.example.download.bean.downloading_item

class BViewModel : ViewModel(){
    private var _downloadingItemList = MutableLiveData<MutableList<downloading_item>>()
    val downloadingItemList: LiveData<MutableList<downloading_item>>get() = _downloadingItemList
    init {
        loadInitialItems()
    }

    private fun loadInitialItems() {
        _downloadingItemList.value = mutableListOf(
            downloading_item(iv_dli_item_imageView = R.drawable.b1, iv_dli_item_title = "How to unlock your iPhone with your Apple Watch — Apple Support", iv_dli_item_date = "20MB/59.51MB", iv_dli_item_speed = "Connection failed,click retry", iv_dli_item_close = R.mipmap.frame945, iv_dli_item_retry = R.mipmap.retry),
            downloading_item(iv_dli_item_imageView = R.drawable.b1, iv_dli_item_title = "How to unlock your iPhone with your Apple Watch — Apple Support", iv_dli_item_date = "20MB/59.51MB", iv_dli_item_speed = "10KB/s", iv_dli_item_close = R.mipmap.frame945, iv_dli_item_retry = R.mipmap.pause)
        )
    }
    fun addNewItem(){
        val newItem = downloading_item(
            iv_dli_item_imageView = R.drawable.b1,
            iv_dli_item_title = "How to unlock your iPhone with your Apple Watch — Apple Support",
            iv_dli_item_date = "20MB/59.51MB",
            iv_dli_item_speed = "10KB/s",
            iv_dli_item_close = R.mipmap.frame945,
            iv_dli_item_retry = R.mipmap.pause
        )
        val updatedList = _downloadingItemList.value ?: mutableListOf()
        updatedList.add(newItem)
        _downloadingItemList.value = updatedList
    }
}